<?php

namespace App\Models\Customer;

use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Model;

/**
 * 客户分组模型类
 *
 * @author WangBin
 * @date 2021-09-24
 * @package App\Models
 */
class Group extends BaseModel
{
    protected $table = 'b2c_customer_group';
    protected $primaryKey = 'group_id';

    /**
     * 获取分组列表（过滤器）
     *
     * @param array $filter
     * @return \Illuminate\Database\Eloquent\Builder|Model|object|null
     */
    public static function getByFilter(array $filter = [])
    {
        $groups = Group::query();
        if(!empty($filter['group_name'])) {
            $groups->where('group_name', 'like', '%' . $filter['group_name'] . '%');
        }
        $groups->orderByDesc('created_at');
        return $groups;
    }
}
